﻿$(function () {
    $("#addAdmin").click(function () {
        if(!Check()){
            return;
        }
        var postdata = "username=" + $.trim($("#username").val())
            + "&email=" + $.trim($("#email").val())
            + "&phone=" + $.trim($("#phone").val())
            + "&pwd=" + $.trim($("#pwd").val())
            + "&confirmPwd=" + $.trim($("#confirmPwd").val());
        // alert(postdata);
        $.post("/admin/adminAdd", postdata, function (data) {
            if (data.code == 200) {
                 alert("添加成功");
                 window.location.href="/admin/adminList";
            } else {
                alert("添加失败,用户名重复");
            }
        }, "json");
    });
});

function Check(){
    if($("#username").val()==""){
        alert("请输入用户名！");
        $("#username").focus();
        return false;
    }
    if($("#email").val()==""){
        alert("请输入邮箱！");
        $("#email").focus();
        return false;
    }
    if($("#phone").val()==""){
        $("#phone").focus();
        alert("请输入联系方式！");
        return false;
    }
    if(!/^[a-zA-Z0-9_+.-]+\@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$/.test($("#email").val())){
        alert("邮箱不合法，请重新输入！");
        $("#email").focus();
        return false;
    }
    if(!/^((13[0-9])|(15[0-9])|(18[0-9]))[0-9]{8}$/.test($("#phone").val())){
        alert("联系方式不合法，请重新输入！");
        $("#email").focus();
        return false;
    }
  // return CheckPassword('pwd','confirmPwd',6);
    if(CheckPassword('pwd','confirmPwd',6)==false){
        return false;
    }
    return true;
}